import * as types from './mutations-type'

const mutactions = {
  /**
   * 初始化画布控制器尺寸
   * @param {{width: number; height: number}} payload
   */
  [types.INIT_CANVAS] (state, payload) {
    state.canvasData.initCanvas(payload.width, payload.height)
  },
  [types.LAYER_ON_CHANGE] (state, payload) {
    const layer = state.canvasData.findLayer(payload)
    return layer
  },
  // 素材上传、删除
  addImgUrl (state, url) {
    state.imgUrlList.push(url)
  },
  deleteImgUrl (state, index) {
    state.imgUrlList.splice(index, 1)
  },
  addToCollect (state, url) {
    // 存在则不添加
    const findResutlt = state.collect.find((x) => x === url)
    if (!findResutlt) {
      state.collect.push(url)
      console.log(state.collect)
      alert('收藏成功')
    } else {
      alert('已存在')
    }
  }
}

export default mutactions
